package com.company.behavioral.mediator_pattern.concrete_mediator;

import com.company.behavioral.mediator_pattern.colleague.Component;
import com.company.behavioral.mediator_pattern.concrete_colleague.Button;
import com.company.behavioral.mediator_pattern.concrete_colleague.ComboBox;
import com.company.behavioral.mediator_pattern.concrete_colleague.List;
import com.company.behavioral.mediator_pattern.concrete_colleague.TextBox;
import com.company.behavioral.mediator_pattern.mediator.Mediator;

;

/**
 * 具体中介者
 * @ClassName ConcreteMediator
 * @Author tiezheng.han
 * @Date 2020/9/4 17:03
 **/
public class ConcreteMediator extends Mediator {

    /**
     * 维持对各个同事对象的引用
     */
    public Button addButton;

    public List list;

    public TextBox userNameTextBox;

    public ComboBox cb;

    /**
     * 封装同事对象之间的交互
     * @param c
     */
    @Override
    public void componentChanged(Component c) {
        // 单击按钮
        if (c == addButton) {
            System.out.println("--单击增加按钮--");
            list.update();
            cb.update();
            userNameTextBox.update();
        } else if (c == list) {
            // 从列表框选择客户
            System.out.println("--从列表框选择客户--");
            cb.select();
            userNameTextBox.setText();
        } else if (c == cb) {
            // 从组合框选择客户
            System.out.println("--从组合框选择用户--");
            cb.select();
            userNameTextBox.setText();
        }
    }
}
